export const noop = () => void 0

export const getBirth = (
	no = '',
	slipt = '-',
	isDate = false,
	isRreverse = false
) => {
	if (!no) return no
	const toStr = no.toString()
	const yearStr = toStr.substring(6, 10)
	const dateStr = `${toStr.substring(10, 12)}${slipt}${toStr.substring(12, 14)}`
	const reulst = isDate ? dateStr : `${yearStr}${slipt}${dateStr}`
	return isRreverse ? reulst.split(slipt).reverse().join(slipt) : reulst
}

export const getAge = (no = '') => {
	if (!no) return no
	const toStr = no.toString()
	const birth = new Date(getBirth(toStr))
	const today = new Date()
	let age = today.getFullYear() - birth.getFullYear()
	if (
		today.getMonth() < birth.getMonth() ||
		(today.getMonth() == birth.getMonth() && today.getDate() < birth.getDate())
	) {
		age--
	}
	return age
}

export const debounce = (func) => {
	var timer

	function exe() {
		if (timer) {
			clearTimeout(timer)
		}
		timer = setTimeout(() => {
			func.call(this, ...arguments)
		}, 144)
	}
	return exe
}

export function isWeChat() {
	var ua = navigator.userAgent.toLowerCase()
	return ua.indexOf('micromessenger') !== -1
}
